#ifndef __WIEGAND_H__
#define __WIEGAND_H__

#define LOG_TAG_WIEGAND "wiegand"

#include <rtthread.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
	wiegand_idle=0, /* 空闲状态 */
	wiegand_receiving=1, /* 正在接收数据 */
}wiegand_state;

typedef struct
{
	wiegand_state stat;
	rt_device_t dev;
	rt_timer_t timer; /* 用于状态处理的定时器 */
	rt_base_t  data0pin;  /* 连接到DATA0的引脚 */
	rt_uint8_t head,tail; /* 用于数据校验前半部校验和后半部校验 */
	rt_uint8_t index; /* 指示目前接收了多少的数据位 */
	rt_uint8_t *data;  /* 实际接收到的数据缓冲区 */
	rt_uint8_t databits;
}wiegand_package;

void wiegand_irq_isr(wiegand_package *wiegand);
rt_err_t wiegand_device_init(char *devname,rt_uint16_t bits,rt_base_t data0pin);


#ifdef __cplusplus
}
#endif

#endif
